Questions
37 of 50
1What is a pseudo-class in CSS?
2How are pseudo-classes different from pseudo-elements?
3What is the syntax of a pseudo-class in CSS?
4Give some commonly used pseudo-classes.
5What does the :hover pseudo-class do?
6What’s the purpose of the :active pseudo-class?
7How does the :visited pseudo-class work for links?
8What is the :focus pseudo-class used for?
9What does the :checked pseudo-class do?
10How does the :disabled pseudo-class behave?
11What is the difference between :first-child and :first-of-type?
12How do :nth-child() and :nth-of-type() differ?
13How do you select every odd or even element using pseudo-classes?
14How can you style an element when it’s being hovered over along with its child?
15What does the :not() pseudo-class do?
16How can you use multiple pseudo-classes together?
17What is the difference between :link and :visited?
18What does the :target pseudo-class represent?
19How can you use :empty to detect empty elements?
20How does the :root pseudo-class differ from the html selector?
21What does the :valid and :invalid pseudo-class do?
22How can you use :required and :optional pseudo-classes in forms?
23What is the use of :in-range and :out-of-range?
24What does :read-only and :read-write do?
25How can you style an input field when it’s autofilled?
26How does the :focus-within pseudo-class work?
27What’s the difference between :focus and :focus-visible?
28What is the purpose of the :placeholder-shown pseudo-class?
29How can you style a checkbox when it is checked or unchecked?
30How can you style invalid form inputs without JavaScript?
31Can pseudo-classes be chained together? Give an example.
32What is the specificity of pseudo-classes compared to normal selectors?
33How can you use :not() effectively to exclude elements from styling?
34How does :has() pseudo-class work, and why is it powerful?
35Is :has() supported in all browsers?
36How does :is() differ from :where() in terms of specificity?
37How can you combine :is() or :where() with other selectors for cleaner code?
38What’s the difference between :nth-child() and :nth-last-child()?
39How can you style only the last element of a list using pseudo-classes?
40What does the :lang() pseudo-class do?
41How do you change a button’s color when hovered but not when disabled?
42How can you highlight the current section in a menu using :target?
43How can you style a form field differently when focused and valid?
44How do you style every third list item differently?
45How can you style alternate table rows without adding extra classes?
46How do you hide empty <p> tags using pseudo-classes?
47How can you style the parent when any child inside it is focused?
48How can you highlight a link only when it’s both focused and hovered?
49How can you style the first letter of only the first paragraph using pseudo-classes?
50How would you use :has() to select a <div> that contains an image?
37 / 50

How can you combine :is() or :where() with other selectors for cleaner code?

Combining :is() and :where() with Other Selectors in CSS

The :is() and :where() pseudo-classes can be combined with type selectors, classes, IDs, and other pseudo-classes to simplify complex CSS selectors and make your code cleaner and more maintainable.

How to Combine :is() and :where()
  1. 1

    Group multiple element types, classes, or pseudo-classes inside :is() or :where() to reduce repetition.

  2. 2

    Combine with child (>) or descendant selectors for precise targeting, e.g., div:is(.card, .panel) > h2.

  3. 3

    Use :where() for default styling without increasing specificity, especially for utility or global styles.

  4. 4

    Combine with pseudo-classes like :hover, :focus, or :nth-child() for interactive or dynamic styling.

Example: Combining :is() with Other Selectors

In this example, :is() groups .card and .panel to style their headings together, :where() sets default paragraph color without increasing specificity, and :is() is also used to apply hover styles to links in multiple parent containers efficiently.

Best Practices
  1. 1

    Use :is() when you want the selectors inside to maintain specificity for overriding purposes.

  2. 2

    Use :where() for fallback or utility styles to avoid specificity conflicts.

  3. 3

    Combine them with combinators and other pseudo-classes for concise and maintainable CSS.

  4. 4

    Test across modern browsers to ensure compatibility and fallback gracefully if necessary.

Difficulty: 6/10
Topics: CSS specificity, selector optimization, maintainable styling

Scenario Questions

0-2 years experience
  1. 1

    You have three buttons with different classes but the same hover style — how would you use :is() to combine them into one rule without repeating the styles?

  2. 2

    If you write :where(.btn, .link, .card) { color: blue; }, what happens to the specificity compared to writing each selector separately?

  3. 3

    You're told to clean up a CSS file with 10 duplicate rules for different form inputs — how would :is() help you reduce that?

2-5 years experience
  1. 1

    A designer says the primary button’s hover state isn’t working anymore — you notice it’s being overridden by a global :where() rule. How do you debug and fix this without breaking other styles?

  2. 2

    Your team’s component library uses :is() to group header variants, but now a new team is adding custom styles that break the pattern. How do you communicate the tradeoff between maintainability and flexibility?

  3. 3

    You’re refactoring a legacy CSS file with 50+ similar rules for .nav-item, .sidebar-link, .footer-link — why might you choose :where() over :is() here, and what could go wrong?

5-8 years experience
  1. 1

    You’re designing a scalable design system where components are reused across 10+ products — how do you decide whether to use :is() or :where() to avoid specificity wars in a global CSS environment?

  2. 2

    A performance audit shows your CSS bundle is bloated due to duplicated selectors. How would you use :is() and :where() to optimize it, and what edge cases might you miss in a large codebase?

  3. 3

    Your team uses :where() to simplify styling, but QA reports inconsistent behavior in IE11 and older Safari. How do you handle browser support while keeping the code clean?

8+ years experience
  1. 1

    You’re leading a migration from a legacy CSS framework to a modern component library — how do you architect the transition to use :is() and :where() without breaking thousands of existing overrides across products?

  2. 2

    Your company has 50+ micro-frontends with inconsistent CSS practices. How would you enforce a consistent pattern for grouping selectors using :is() and :where() across teams, and what governance or tooling would you put in place?

  3. 3

    You’re evaluating whether to adopt :where() for all low-specificity resets in your global stylesheet. What long-term maintenance risks do you foresee, and how would you mitigate them in a 10-year codebase?

Follow-up Questions

  • How would you decide between :is() and :where() if you're seeing unexpected styles being overridden?
  • What happens if you nest :is() inside another complex selector — does specificity change?
  • Have you ever used these pseudo-classes to refactor legacy CSS? What challenges did you run into?